

clear 
set scheme lean2, permanent
global pm = char(177) 
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  
 
global path_data_processed "\data\processed"
global path_output "\data\output"
 
clear all
set more off

cd "$path_data_processed"
use "experimentRNall.dta", clear

cd "$path_output"
 

corr updating_f updating
 
lpoly updating shock

lpoly updating_f shock

gen prior_high_conf=(prior_conf>3) 
gen shock_prior_high_conf=shock*prior_high_conf
gen prior_prior_high_conf=prior*prior_high_conf

gen shock_highprior = highprior*shock


gen shock_negative=0
gen cons=1

replace shock_negative=shock if shock<0 // present this as well: Updating symmetric.

gen nonews=(follow_news<=2)
gen shock_nonews=shock*nonews

gen dofollownews=(follow_news>=3)
gen shock_dofollownews=shock*dofollownews
gen prior_dofollownews=prior*dofollownews


foreach var of varlist republican democrat finlit_index{
gen mis_`var' = `var'==.
replace `var'=0 if `var'==.
}

    reg updating shock shock_highprior highprior prior  $controls, r noconstant


replace log_income=0 if inc_NR==1
global controls age agesq female log_income inc_NR atleast_bachelor midwest south west republican democrat finlit_index mis_republican mis_finlit_index
 
loc experiments "updating updating updating updating updating updating_f updating_f"

preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""






***OLS



    reg updating shock prior cons $controls, r noconstant
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col1
    estadd loc thisstat3 = "`r(sestar)'": col1
	sigstar prior, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col1
    estadd loc thisstat18 = "`r(sestar)'": col1
	qui sum updating
    estadd loc thisstat20 = r(N): col1
	estadd loc thisstat22 = "Baseline": col1
	
	reg updating shock shock_prior_high_conf prior_high_conf prior prior_prior_high_conf cons $controls, r noconstant
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col2
    estadd loc thisstat3 = "`r(sestar)'": col2
	sigstar shock_prior_high_conf, prec(3)
    estadd loc thisstat5 = "`r(bstar)'": col2
    estadd loc thisstat6 = "`r(sestar)'": col2
	sigstar prior_high_conf, prec(3)
    estadd loc thisstat8 = "`r(bstar)'": col2
    estadd loc thisstat9 = "`r(sestar)'": col2
	sigstar prior, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col2
    estadd loc thisstat18 = "`r(sestar)'": col2
	qui sum updating
    estadd loc thisstat20 = r(N): col2
	estadd loc thisstat22 = "Baseline": col2
		
    reg updating shock shock_dofollownews dofollownews prior prior_dofollownews cons $controls, r noconstant
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col3
    estadd loc thisstat3 = "`r(sestar)'": col3
	sigstar shock_dofollownews, prec(3)
    estadd loc thisstat11 = "`r(bstar)'": col3
    estadd loc thisstat12 = "`r(sestar)'": col3
	sigstar dofollownews, prec(3)
    estadd loc thisstat14 = "`r(bstar)'": col3
    estadd loc thisstat15 = "`r(sestar)'": col3
	sigstar prior, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col3
    estadd loc thisstat18 = "`r(sestar)'": col3
	qui sum updating
    estadd loc thisstat20 = r(N): col3
	estadd loc thisstat22 = "Baseline": col3
   
    reg updating shock prior cons $controls if updating_f!=., r noconstant
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col4
    estadd loc thisstat3 = "`r(sestar)'": col4
	sigstar prior, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col4
    estadd loc thisstat18 = "`r(sestar)'": col4
	qui sum updating if updating_f!=.
    estadd loc thisstat20 = r(N): col4	
	estadd loc thisstat22 = "Basel. (compl.": col4
	estadd loc thisstat23 = "follow-up)": col4
		
	reg updating_f shock prior cons $controls if updating_f!=., r noconstant
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col5
    estadd loc thisstat3 = "`r(sestar)'": col5
	sigstar prior, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col5
    estadd loc thisstat18 = "`r(sestar)'": col5
	qui sum updating_f if updating_f!=.
    estadd loc thisstat20 = r(N): col5
	estadd loc thisstat22 = "Follow-up": col5
  
    reg updating_f shock shock_prior_high_conf prior_high_conf prior prior_prior_high_conf cons $controls if updating_f!=., r noconstant
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col6
    estadd loc thisstat3 = "`r(sestar)'": col6
	sigstar shock_prior_high_conf, prec(3)
    estadd loc thisstat5 = "`r(bstar)'": col6
    estadd loc thisstat6 = "`r(sestar)'": col6
	sigstar prior_high_conf, prec(3)
    estadd loc thisstat8 = "`r(bstar)'": col6
    estadd loc thisstat9 = "`r(sestar)'": col6
	sigstar prior, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col6
    estadd loc thisstat18 = "`r(sestar)'": col6
	qui sum updating_f if updating_f!=.
    estadd loc thisstat20 = r(N): col6
	estadd loc thisstat22 = "Follow-up": col6
	
	reg updating_f shock shock_dofollownews dofollownews prior prior_dofollownews cons $controls, r noconstant
    sigstar shock, prec(3)
    estadd loc thisstat2 = "`r(bstar)'": col7
    estadd loc thisstat3 = "`r(sestar)'": col7
	sigstar shock_dofollownews, prec(3)
    estadd loc thisstat11 = "`r(bstar)'": col7
    estadd loc thisstat12 = "`r(sestar)'": col7
	sigstar dofollownews, prec(3)
    estadd loc thisstat14 = "`r(bstar)'": col7
    estadd loc thisstat15 = "`r(sestar)'": col7
	sigstar prior, prec(3)
    estadd loc thisstat17 = "`r(bstar)'": col7
    estadd loc thisstat18 = "`r(sestar)'": col7
	qui sum updating_f if updating_f!=.
    estadd loc thisstat20 = r(N): col7
	estadd loc thisstat22 = "Follow-up": col7
	
	loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"



loc rowlabels " " " "Shock" " " " " "Shock $\times$" "Confident" " " "Confident" " " " " "Shock $\times$" "Follow news" " " "Follow news" " " " " "Prior" " " " " "Observations" " " "Sample" " "    "
loc rowstats ""

forval i = 1/23 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "learningrate.tex", replace cells(none) booktabs nonotes nomtitles /*nonum*/ compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
      mgroups("Updating (Main Survey)" "Updating (Follow-up)" , pattern(1 0 0 0 1 0 0 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

eststo clear	








